/*********************************************************************
*
*	 File: obj.h
*	 Declare properties and methods of Object
*	 Is is abstract class
*	 Author: 10520418 Bui Huu Hiep
*
**********************************************************************/
#ifndef _OBJ_H
#define _OBJ_H

#include "Sprite.h"
#include "Input.h"
#include <vector>
#include <algorithm>
#include "Resources.h"
#include "InfoObject.h"
#include "QNode.h"

#define GRAVITY 2000

using namespace std;

class QNode;

// Id of all Objects in Game
enum ID
{
	None,
	ID_Mario,
	ID_Land,
	ID_Brick,
	ID_StoneA,
	ID_MushGreen,
	ID_MushRed,
	ID_Flower,
	ID_Star,
	ID_Coin,
	ID_QBrick,
	ID_StoneB,
	ID_Goomba,
	ID_EatFlower,
	ID_Koopa,
	ID_Pipe1,
	ID_Pipe2,
	ID_Pipe3,
	ID_Grass,
	ID_Cloud,
	ID_Mountain,
	ID_PipeSpecial,
	ID_House,
	ID_Ladder,
	ID_Boss,
	ID_FireBoss,
	ID_Bullet,
};

class GameObject
{
protected:
	Sprite*			_sprite;			// Animation of Object

	float			_pos_x;				// Position X
	float			_pos_y;				// Position Y

	float			_vel_x;				// Velocity X
	float			_vel_y;				// Velocity Y

	float			_acc_x;				// Acceleration X
	float			_acc_y;				// Acceleration Y

	float			_width;				// Width of object (pixel)
	float			_height;			// Height of object (pixel)

	int				_id;				// Kind object
	int				_direction;			// Direction of object (Left = 0, Right = 1)
	char			_state;

	RECT			_rect;				// Rectangle bounding Object
	RECT			_old_rect;			// Rectangle bouding Object before it moved
	RECT			_rom;

	bool			_isAlive;			// If object die, _isAlive = false and backwards

	float			_old_x;				// Position X before move
	float			_old_y;				// Position Y before move
	bool			_isStatic;			// If object is a static object, _isStatic = true and backwards

	Resources*		_resources;			// Resources pointer, it contains all Texture, Surface and Sound use for Game

	int				_moreover;			// Save some info depend on object
	int				_depth;				// Render before or after

	int				_number;			// Use when Save Object
public:
	// Constructor and Destructor
	GameObject(int posX, int posY, int width, int height, Resources* res, int number, int depth);
	~GameObject();

	// Update Object
	virtual void Update(float time, QNode* &Tree);
	
	// Draw Object
	virtual void Render(LPD3DXSPRITE spriteHandler,	Viewport* viewport);
	
	// Update Rectangle bounding Object
	void ResetRect();

	// Change state of Object
	virtual	void ChangeState(char state);

	//_____________________________________________________
	// Get or Set Some Properties
	float PosX() { return _pos_x; }
	float PosY() { return _pos_y; }

	void SetPosX(float value) { _pos_x = value; }
	void SetPosY(float value) { _pos_y = value; }

	float OldPosX() { return _old_x; }
	float OldPosY() { return _old_y; }

	float Vx() { return _vel_x; }
	float Vy() { return _vel_y; }

	float Ax() { return _acc_x; }
	float Ay() { return _acc_y; }

	float Width() { return _width; }
	float Height() { return _height; }

	void Width(float width) { _width = width; }
	void Height(float height) { _height = height; }

	D3DXVECTOR2	Max() { return D3DXVECTOR2(_rect.right, _rect.bottom); }
	D3DXVECTOR2 Min() { return D3DXVECTOR2(_rect.left, _rect.top); }

	RECT Rect() { return _rect; }
	RECT OldRect() { return _old_rect; }

	int ID() { return _id; }

	char GetState() { return _state; }
	bool GetIsStatic(){ return _isStatic; }
	bool GetIsAlive() { return _isAlive; }
	void SetIsAlive(bool val) { _isAlive = val; }
	void SetVx(float val) { _vel_x = val; }

	int MoreOver(){ return _moreover; }
	void MoreOver(int val) { _moreover = val; }
	int Depth() { return _depth; }
	
	int Number() { return _number; }
	void Number(int val){ _number = val; }
	//________________________________________________________________________
	float			TimeCollision;		// Time collision
};
#endif
